﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Web.Mvc;
using StockPredictor.Models;
using StockPredictor.App_Start;
using StockPredictor.Utilities;

namespace StockPredictor.Controllers
{
    public class YahooFinanceController : Controller
    {
        //
        // GET: /YahooFinance/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection fc, string SearchSymbols)
        {
            string[] searchString = SearchSymbols.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            // retrieve stock data
            List<CurrentStock> stocks = YahooFinance.GetCurrentStockData(searchString, "");
            return View(stocks);
        }

        public JsonResult ChartResults(string stockSymbol)
        {
            var results = StockChartHelper.GetChartResults(stockSymbol);
            var jsonResult = Json(results.Select(x => new[] { x.x, x.open, x.high, x.low, x.close }));
            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return jsonResult;
        }

    }
}
